﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Users.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
    <title>Time Tracker - Home</title>
    <script type="text/javascript" src="script.js"></script>
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" />
    <link rel="shortcut icon" href="timetracker.ico" />
    <link rel="icon" type="image/vnd.microsoft.icon" href="timetracker.ico" />
    <!--[if IE 6]><link rel="stylesheet" href="style.ie6.css" type="text/css" media="screen" /><![endif]-->
    <!--[if IE 7]><link rel="stylesheet" href="style.ie7.css" type="text/css" media="screen" /><![endif]-->
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div id="art-page-background-simple-gradient">
    </div>
    <div id="art-page-background-glare">
    </div>
    <div id="art-main">
        <div class="art-Sheet">
            <div class="art-Sheet-tl">
            </div>
            <div class="art-Sheet-tr">
            </div>
            <div class="art-Sheet-bl">
            </div>
            <div class="art-Sheet-br">
            </div>
            <div class="art-Sheet-tc">
            </div>
            <div class="art-Sheet-bc">
            </div>
            <div class="art-Sheet-cl">
            </div>
            <div class="art-Sheet-cr">
            </div>
            <div class="art-Sheet-cc">
            </div>
            <div class="art-Sheet-body">
                <div class="art-nav">
                    <div class="l">
                    </div>
                    <div class="r">
                    </div>
                    <ul class="art-menu">
                        <li>
                            <asp:HyperLink ID="HyperLinkMain" runat="server" NavigateUrl="~/Default.aspx"><span class="l"></span><span class="r"></span><span class="t">Home</span></asp:HyperLink>
                        </li>
                        <%if (User.IsInRole("Administrator"))
                          { %>
                        <li>
                            <asp:HyperLink ID="HyperLinkEmployee" runat="server" NavigateUrl="~/Users.aspx"><span class="l"></span><span class="r"></span><span class="t">Manage User</span></asp:HyperLink>
                        </li>
                        <li>
                            <asp:HyperLink ID="HyperSettings" runat="server" NavigateUrl="~/Settings.aspx"><span class="l"></span><span class="r"></span><span class="t">Manage Settings</span></asp:HyperLink>
                        </li>
                        <%} %>
                        <li>
                            <asp:LinkButton ID="LinkButtonLogOut" runat="server" OnClick="Click_Logout"><span class="l"></span><span class="r"></span><span class="t">Log Out</span></asp:LinkButton>
                        </li>
                    </ul>
                </div>
                <div class="art-Header">
                    <div class="art-Header-jpeg">
                    </div>
                    <div class="art-Logo">
                        <h1 id="name-text" class="art-Logo-name">
                            <a href="#">Time Tracker</a></h1>
                    </div>
                </div>
                <div class="art-contentLayout">
                    <div class="art-content2">
                        <div class="art-Post">
                            <div class="art-Post-body">
                                <asp:Panel ID="PanelEmployee" runat="server">
                                    <fieldset>
                                        <legend>Employees</legend>
                                        <div class="art-article">
                                            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                                                AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSourceEmployees"
                                                EnableModelValidation="True" OnRowCommand="EmployeeCommand" CellPadding="4" ForeColor="#333333"
                                                GridLines="None" CssClass="Center" Width="100%">
                                                <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                                <Columns>
                                                    <asp:CommandField ShowDeleteButton="True" ButtonType="Button" />
                                                    <asp:TemplateField HeaderText="Admin">
                                                        <ItemTemplate>
                                                            <%# System.Web.Security.Roles.IsUserInRole(Eval("emailAddress").ToString(),"Administrator").ToString()%></ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                                                        SortExpression="ID" />
                                                    <asp:BoundField DataField="firstName" HeaderText="First Name" SortExpression="firstName" />
                                                    <asp:BoundField DataField="lastName" HeaderText="Last Name" SortExpression="lastName" />
                                                    <asp:BoundField DataField="emailAddress" HeaderText="Email Address" SortExpression="emailAddress" />
                                                    <asp:ButtonField ButtonType="Button" CommandName="ChangeRole" Text="Change Role">
                                                        <HeaderStyle Wrap="False" />
                                                        <ItemStyle Wrap="False" />
                                                    </asp:ButtonField>
                                                </Columns>
                                                <EditRowStyle BackColor="#999999" />
                                                <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                                <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                                <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                                <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                                <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                            </asp:GridView>
                                            <asp:Button ID="LinkButtonCreateEmp" runat="server" Text="Create Employee" OnClick="CreateUser"/>
                                        </div>
                                        <br />
                                        <div style="margin: auto;">
                                            <asp:CreateUserWizard ID="CreateUserWizardMain" runat="server" CancelDestinationPageUrl="~/Default.aspx"
                                                LoginCreatedUser="False" UserNameLabelText="Email Address" UserNameRequiredErrorMessage="Email Address is required."
                                                OnCreatedUser="CreatedUser" OnCreatingUser="CreatingUser" FinishDestinationPageUrl="~/Users.aspx"
                                                Visible="False" CssClass="Center" ContinueDestinationPageUrl="Users.aspx">
                                                <WizardSteps>
                                                    <asp:CreateUserWizardStep ID="CreateUserWizardStep2" runat="server" Title="Create a  New Employee Account">
                                                        <ContentTemplate>
                                                            <table border="0">
                                                                <tr>
                                                                    <td align="center" colspan="2">
                                                                        Create a New Employee Account
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td align="right">
                                                                        <asp:Label ID="LabelFirstName" runat="server" AssociatedControlID="FirstName">First Name</asp:Label>
                                                                    </td>
                                                                    <td>
                                                                        <asp:TextBox ID="FirstName" runat="server"></asp:TextBox>
                                                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FirstName"
                                                                            ErrorMessage="The employee's first name is required." ToolTip="First name is required."
                                                                            ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td align="right">
                                                                        <asp:Label ID="LabelLastName" runat="server" AssociatedControlID="LastName">Last Name</asp:Label>
                                                                    </td>
                                                                    <td>
                                                                        <asp:TextBox ID="LastName" runat="server"></asp:TextBox>
                                                                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="LastName"
                                                                            ErrorMessage="Last name is required." ToolTip="Last name is required." ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td align="right">
                                                                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                                                                    </td>
                                                                    <td>
                                                                        <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                                                                        <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
                                                                            ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td align="right">
                                                                        <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
                                                                    </td>
                                                                    <td>
                                                                        <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
                                                                        <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" ControlToValidate="ConfirmPassword"
                                                                            ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
                                                                            ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td align="right">
                                                                        <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
                                                                    </td>
                                                                    <td>
                                                                        <asp:TextBox ID="Email" runat="server"></asp:TextBox>
                                                                        <asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="Email"
                                                                            ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                        <asp:TextBox ID="UserName" runat="server" Visible="false"></asp:TextBox>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td align="center" colspan="2">
                                                                        <asp:CompareValidator ID="PasswordCompare" runat="server" ControlToCompare="Password"
                                                                            ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                                                                            ValidationGroup="CreateUserWizardMain"></asp:CompareValidator>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td align="center" colspan="2" style="color: Red;">
                                                                        <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </ContentTemplate>
                                                    </asp:CreateUserWizardStep>
                                                    <asp:CompleteWizardStep ID="CompleteWizardStep2" runat="server">
                                                        <ContentTemplate>
                                                            <table border="0">
                                                                <tr>
                                                                    <td align="center" colspan="2">
                                                                        Complete
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        Your account has been successfully created.
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td align="right" colspan="2">
                                                                        <asp:Button ID="ContinueButton" runat="server" CausesValidation="False" CommandName="Continue"
                                                                            Text="Continue" ValidationGroup="CreateUserWizardMain" />
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </ContentTemplate>
                                                    </asp:CompleteWizardStep>
                                                </WizardSteps>
                                            </asp:CreateUserWizard>
                                        </div>
                                    </fieldset>
                                </asp:Panel>
                                <asp:SqlDataSource ID="SqlDataSourceEmployees" runat="server" ConnectionString="<%$ ConnectionStrings:TimeTrackerConnectionString1 %>"
                                    DeleteCommand="DELETE FROM [Employee] WHERE [ID] = @ID" InsertCommand="INSERT INTO [Employee] ([firstName], [lastName], [emailAddress]) VALUES (@firstName, @lastName, @emailAddress)"
                                    SelectCommand="SELECT [ID], [firstName], [lastName], [emailAddress] FROM [Employee] ORDER BY [lastName], [firstName]"
                                    UpdateCommand="UPDATE [Employee] SET [firstName] = @firstName, [lastName] = @lastName, [emailAddress] = @emailAddress WHERE [ID] = @ID">
                                    <DeleteParameters>
                                        <asp:Parameter Name="ID" Type="Int32" />
                                    </DeleteParameters>
                                    <UpdateParameters>
                                        <asp:Parameter Name="firstName" Type="String" />
                                        <asp:Parameter Name="lastName" Type="String" />
                                        <asp:Parameter Name="emailAddress" Type="String" />
                                        <asp:Parameter Name="ID" Type="Int32" />
                                    </UpdateParameters>
                                    <InsertParameters>
                                        <asp:Parameter Name="firstName" Type="String" />
                                        <asp:Parameter Name="lastName" Type="String" />
                                        <asp:Parameter Name="emailAddress" Type="String" />
                                    </InsertParameters>
                                </asp:SqlDataSource>
                                <asp:Panel ID="PanelCustomer" runat="server">
                                    <fieldset>
                                        <legend>Customers</legend>
                                        <div class="art-article">
                                        <asp:GridView ID="GridViewCustomers" runat="server" EnableModelValidation="True"
                                            CellPadding="4" ForeColor="#333333" GridLines="None" Width="100%" 
                                            onrowcommand="CustomerCommands" AutoGenerateColumns="False" DataKeyNames="UserName">
                                            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                                            <EditRowStyle BackColor="#999999" />
                                            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                                            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                                            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                                            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                                            <Columns>
                                                <asp:BoundField DataField="UserName" HeaderText="Name"></asp:BoundField>
                                                <asp:TemplateField HeaderText="Company"><ItemTemplate><%# GetCustomerName((string)Eval("UserName"))%></ItemTemplate></asp:TemplateField>
                                                <asp:BoundField DataField="LastLoginDate" HeaderText="Last Logged In"></asp:BoundField>
                                                <asp:BoundField DataField="Email" HeaderText="Email"></asp:BoundField>
                                                <asp:ButtonField ButtonType="Button" CommandName="UserDelete" Text="Delete" />
                                            </Columns>
                                        </asp:GridView>
                                        </div>
                                        <asp:ObjectDataSource ID="ObjectDataSourceCustomers" runat="server"></asp:ObjectDataSource>
                                        <asp:Button ID="LinkButtonCreateCustomer" runat="server" Text="Create Customer"  OnClick="CreateCustomerUser"/>
                                        <asp:CreateUserWizard ID="CreateCustomerUserWizard" runat="server" CancelDestinationPageUrl="~/Default.aspx"
                                            LoginCreatedUser="False" UserNameLabelText="Email Address" UserNameRequiredErrorMessage="Email Address is required."
                                            OnCreatedUser="CreatedCustomerUser" OnCreatingUser="CreatingCustomerUser" FinishDestinationPageUrl="~/Users.aspx"
                                            Visible="False" CssClass="Center" ContinueDestinationPageUrl="Users.aspx">
                                            <WizardSteps>
                                                <asp:WizardStep ID="CustomerSelection" runat="server" Title="Select Customer">
                                                    <asp:Label ID="Label1" runat="server" Text="Company: "></asp:Label>
                                                    <asp:DropDownList ID="DropDownListCustomers" runat="server" DataSourceID="LinqDataSourceCustomers"
                                                        DataTextField="customerName" DataValueField="id" Width="254px">
                                                    </asp:DropDownList>
                                                    <asp:LinqDataSource ID="LinqDataSourceCustomers" runat="server" ContextTypeName="TimeTrackerDataContext"
                                                        TableName="Customers">
                                                    </asp:LinqDataSource>
                                                </asp:WizardStep>
                                                <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" 
                                                    Title="Create a New Customer Account">
                                                    <ContentTemplate>
                                                        <table border="0">
                                                            <tr>
                                                                <td align="center" colspan="2">
                                                                    Create a New Customer Account
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                    <asp:Label ID="LabelFirstName" runat="server" AssociatedControlID="FirstName">First Name</asp:Label>
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="FirstName" runat="server"></asp:TextBox>
                                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                                                                        ControlToValidate="FirstName" 
                                                                        ErrorMessage="The employee's first name is required." 
                                                                        ToolTip="First name is required." ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                    <asp:Label ID="LabelLastName" runat="server" AssociatedControlID="LastName">Last Name</asp:Label>
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="LastName" runat="server"></asp:TextBox>
                                                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                                                                        ControlToValidate="LastName" ErrorMessage="Last name is required." 
                                                                        ToolTip="Last name is required." ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                    <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                                                                    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" 
                                                                        ControlToValidate="Password" ErrorMessage="Password is required." 
                                                                        ToolTip="Password is required." ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                    <asp:Label ID="ConfirmPasswordLabel" runat="server" 
                                                                        AssociatedControlID="ConfirmPassword">Confirm Password:</asp:Label>
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="ConfirmPassword" runat="server" TextMode="Password"></asp:TextBox>
                                                                    <asp:RequiredFieldValidator ID="ConfirmPasswordRequired" runat="server" 
                                                                        ControlToValidate="ConfirmPassword" 
                                                                        ErrorMessage="Confirm Password is required." 
                                                                        ToolTip="Confirm Password is required." ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right">
                                                                    <asp:Label ID="EmailLabel" runat="server" AssociatedControlID="Email">E-mail:</asp:Label>
                                                                </td>
                                                                <td>
                                                                    <asp:TextBox ID="Email" runat="server"></asp:TextBox>
                                                                    <asp:RequiredFieldValidator ID="EmailRequired" runat="server" 
                                                                        ControlToValidate="Email" ErrorMessage="E-mail is required." 
                                                                        ToolTip="E-mail is required." ValidationGroup="CreateUserWizardMain">*</asp:RequiredFieldValidator>
                                                                    <asp:TextBox ID="UserName" runat="server" Visible="false"></asp:TextBox>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="center" colspan="2">
                                                                    <asp:CompareValidator ID="PasswordCompare" runat="server" 
                                                                        ControlToCompare="Password" ControlToValidate="ConfirmPassword" 
                                                                        Display="Dynamic" 
                                                                        ErrorMessage="The Password and Confirmation Password must match." 
                                                                        ValidationGroup="CreateUserWizardMain"></asp:CompareValidator>
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="center" colspan="2" style="color: Red;">
                                                                    <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="False"></asp:Literal>
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </ContentTemplate>
                                                </asp:CreateUserWizardStep>
                                                <asp:CompleteWizardStep ID="CompleteWizardStep1" runat="server">
                                                    <ContentTemplate>
                                                        <table border="0">
                                                            <tr>
                                                                <td align="center" colspan="2">
                                                                    Complete
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td>
                                                                    Your account has been successfully created.
                                                                </td>
                                                            </tr>
                                                            <tr>
                                                                <td align="right" colspan="2">
                                                                    <asp:Button ID="ContinueButton" runat="server" CausesValidation="False" CommandName="Continue"
                                                                        Text="Continue" ValidationGroup="CreateUserWizardMain" />
                                                                </td>
                                                            </tr>
                                                        </table>
                                                    </ContentTemplate>
                                                </asp:CompleteWizardStep>
                                            </WizardSteps>
                                        </asp:CreateUserWizard>
                                    </fieldset>
                                </asp:Panel>
                                <asp:Button ID="ButtonEditUser" runat="server" Text="Edit Your Profile" OnClick="EditPersonalProfile" />
                                <asp:Panel ID="PanelPersonal" runat="server" Visible="False">
                                    <div style="margin: 0px auto; width: 350px;">
                                        <asp:ChangePassword ID="ChangePassword1" runat="server">
                                        </asp:ChangePassword>
                                    </div>
                                    <div style="margin:0px auto; width:350px;">
                                        <table width="100%">
                                            <tr>
                                                <td>
                                                    <asp:Label ID="Label2" runat="server" Text="First Name"></asp:Label>
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="TextBoxFirstName" runat="server"></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="Label3" runat="server" Text="Last Name">
                                                    </asp:Label>
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="TextBoxLastName" runat="server"></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="Label4" runat="server" Text="Email Address">
                                                    </asp:Label>
                                                </td>
                                                <td>
                                                    <asp:TextBox ID="TextBoxEmail" runat="server"></asp:TextBox>
                                                </td>
                                            </tr>
                                            <tr><td colspan="2">
                                                <asp:Button ID="ButtonSubmitProfile" runat="server" Text="Submit" 
                                                    onclick="btnSubmitProfile" /></td></tr>
                                        </table>

                                    </div>
                                </asp:Panel>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="cleared">
                </div>
                <div class="art-Footer">
                    <div class="art-Footer-inner">
                        <div class="art-Footer-text">
                            <p>
                                <a href="#">Terms of Use</a> | <a href="#">Privacy Statement</a><br />
                                Copyright &copy;
                                <%# System.DateTime.Now.Year.ToString()%>.
                                All Rights Reserved.</p>
                        </div>
                    </div>
                    <div class="art-Footer-background">
                    </div>
                </div>
                <div class="cleared">
                </div>
            </div>
        </div>
        <div class="cleared">
        </div>
    </div>
    </form>
</body>
</html>
